import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/icons/index'
import './assets/css/global.css'
import { formatDict,formatDict2 } from "./utils/dictionaryUtil"
import {getCurrentTimeType,resetForm,reset1Form,getAge} from "./utils/his-utils"
import moment from 'moment'

Vue.prototype.reset1Form = reset1Form
Vue.prototype.resetForm = resetForm
Vue.prototype.getAge = getAge
Vue.prototype.formatDict = formatDict;
Vue.prototype.formatDict2 = formatDict2;
Vue.prototype.getCurrentTimeType = getCurrentTimeType;
Vue.prototype.moment = moment
import * as echarts from 'echarts';
Vue.prototype.$echarts =echarts;

// 注册mavon-editor组件
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor);

// 挂载全局消息框
Vue.prototype.msgSuccess = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'success' })
}
Vue.prototype.msgError = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'error' })
}



router.beforeEach((to, from, next) => {
  let path = to.path;
  if (path == '/login') {
    return next();
  }
  let token = sessionStorage.getItem("token");
  if (token) {
    return next();
  }
  return next("/login");
});

import ax from "axios";
// 创建实例时配置默认值
const instance = ax.create({
  baseURL: 'http://localhost:8886/'
});
// 添加请求拦截器
instance.interceptors.request.use(config => {
  let token = sessionStorage.getItem("token");
  if (token) {
    config.headers.token = token;
  }
  return config;
});
 // 添加响应拦截器
// configinstance.interceptors.response.use(response => {
//   if(response.data.code===2000){
//     return response;
//   }else if(response.data.code===4001){
//     alert("权限不足");
//     return Promise.reject(new Error())
//   }else if (response.data.code===5000){
//     Vue.prototype.$message.error(response.data.msg);
//     return Promise.reject(new Error())
//   }else if (response.data.code===4002){
//     Vue.prototype.$message.error(response.data.msg);
//     return Promise.reject(new Error())
//   }else {
//     Vue.prototype.$message.error("响应错误");
//     return Promise.reject(new Error())
//   }
// });
Vue.prototype.$axios = instance;


import qs from 'qs';
Vue.prototype.$qs = qs;

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
